package org.xx.armory.db.impl;

import org.xx.armory.commons.CalledBy;
import org.xx.armory.db.DbException;
import org.xx.armory.db.Session;
import org.xx.armory.db.SessionFactory;

import static org.xx.armory.commons.Validators.notNull;

/**
 * @author Haart
 */
class OracleSessionFactory
        extends AbstractSessionFactory {
    @CalledBy("SessionFactories")
    public OracleSessionFactory() {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Session newSession() {
        final OracleSession session = new OracleSession(getTransactionManager().current());
        try {
            session.initialize();
            return session;
        } catch (Exception ex) {
            throw new DbException("cannot initialize session", ex);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public SessionFactory fork() {
        final OracleSessionFactory other = null;
        forkTo(other);
        return other;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void forkTo(
            SessionFactory other
    ) {
        notNull(other, "other");

        super.forkTo(other);
    }

}
